#include <cmath>
#include <iostream>
#include <vector>

// 等同于 numpy.linalg.norm
bool vector_normalize(std::vector<float>& vec) {
    float power_sum = 0.0;
    for (int i = 0; i < vec.size(); ++i) {
        power_sum += vec[i] * vec[i];
    }
    power_sum = sqrt(power_sum);

    for (int i = 0; i < vec.size(); ++i) {
        vec[i] = vec[i] / power_sum;
    }

    return true;
}

int main() {
    std::vector<float> vec = {
        0.46585,    -0.174796,   0.232257,    0.246735,   0.118725,
        -0.178251,  -0.0395333,  0.170718,    -0.161156,  -0.0645382,
        0.118333,   0.286513,    -0.211658,   -0.439381,  0.0109153,
        -0.0405591, -0.13501,    -0.344136,   -0.033783,  0.0814525,
        -0.467996,  -0.227959,   -0.290822,   -0.0321769, 0.197691,
        -0.287023,  -0.253599,   0.286392,    -0.270986,  -0.165623,
        0.201208,   -0.0167197,  0.521144,    0.286934,   -0.046837,
        0.231128,   -0.198387,   0.218315,    -0.0163178, 0.448275,
        -0.0451181, 0.585235,    -0.0407263,  -0.164333,  0.235793,
        -0.181231,  -0.228625,   -0.524188,   0.255007,   0.0293313,
        -0.0658883, 0.342708,    0.183541,    0.0560469,  -0.147565,
        2.13475,    0.113728,    -0.212292,   -0.0839279, -0.0498135,
        -0.438843,  -0.0359045,  -0.0618416,  -0.0831727, 0.144429,
        0.26389,    0.120499,    -0.00466819, -0.039981,  0.0585306,
        -0.203896,  0.186612,    0.409231,    -0.133566,  0.346819,
        -0.145676,  -0.0447405,  -0.179846,   -0.164094,  0.271256,
        0.180508,   -0.199062,   0.00302946,  -0.0130343, 0.280048,
        -0.152627,  -0.152609,   0.153552,    0.565904,   0.179245,
        0.12666,    0.206881,    -0.375908,   -0.527519,  0.11566,
        -0.0270827, -0.16289,    -0.0443759,  0.0800235,  -0.369261,
        0.052901,   -0.0354641,  -0.294768,   -0.413457,  -0.0898862,
        0.0516811,  -0.0176618,  0.179141,    0.12945,    0.432426,
        0.105456,   -0.120128,   0.00320798,  0.117513,   0.108703,
        0.163256,   0.265837,    0.131453,    -0.394229,  -0.0526943,
        -0.0277253, 0.238323,    0.206677,    -0.0213214, -0.601571,
        0.0249053,  -0.0441374,  0.130543,    -0.237803,  0.352341,
        0.128205,   -0.190795,   0.0271509,   -0.0743254, -0.327147,
        0.0685187,  -0.146454,   -0.150218,   0.2245,     -0.0221118,
        0.192514,   0.525905,    0.0906912,   -0.166061,  -0.219179,
        -0.51392,   0.122428,    0.042681,    -0.347997,  -0.459925,
        -0.135606,  0.0442598,   0.213373,    -0.238954,  0.0578798,
        0.0130633,  -0.0851378,  -0.276853,   -0.51757,   0.4444,
        -0.0293322, 0.167273,    0.222205,    -0.199285,  0.129337,
        -0.243412,  -0.284279,   0.106467,    0.0864725,  -0.434644,
        0.416679,   0.00275845,  -0.509334,   -0.176308,  -0.213426,
        0.193486,   -0.382201,   0.118417,    -0.306678,  0.117777,
        -0.126304,  -0.690819,   -0.225902,   -0.205751,  0.181919,
        -0.136271,  0.130247,    -0.42489,    -0.0533622, 0.270528,
        0.330227,   0.226767,    -0.0239545,  0.255241,   0.170777,
        0.0429252,  -0.121861,   0.095514,    -0.393011,  0.219323,
        -0.0349103, 0.350543,    -0.040946,   -0.285137,  0.342467,
        -0.0352041, 0.000705181, -0.0785211,  -0.100515,  0.042968,
        0.136323,   -0.144842,   -0.184649,   0.480573,   0.144643,
        0.176577,   -0.11455,    -0.0243753,  0.156703,   -0.332866,
        0.313937,   0.117375,    -0.0883497,  -0.021423,  0.0810395,
        -0.40264,   -0.0846217,  0.0502606,   0.246524,   -0.356437,
        0.0875216,  -0.0199303,  0.472692,    0.0419651,  0.248803,
        0.430066,   0.270353,    0.221999,    -0.150114,  -0.0145036,
        0.0167735,  0.284146,    0.0491477,   0.308532,   -0.0563134,
        0.484163,   -0.0250989,  -0.179303,   0.0393484,  -0.0439014,
        -0.184599,  -0.152392,   -0.0900532,  -0.22928,   0.0782922,
        -0.0339367};

    vector_normalize(vec);

    for (int i = 0; i < vec.size(); ++i) {
        std::cout << vec[i] << ",";
    }
}

// gcc -std=c++11 vector_normalize.cpp -lstdc++ -o main && ./main